<template>
  <div>
    <el-dialog title="提示" :visible.sync="show" width="30%">
      <input type="text" v-model="str" />
      <el-tree
        :data="showData"
        empty-text="没有数据"
        :show-checkbox="true"
        :accordion="true"
        node-key="NOPS"
        ref="treeForm"
        :check-strictly="true"
        :props="defaultProps"
        :filter-node-method="filterNode"
      ></el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isshow(false)">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      str: '',
      showData: [],
      data: [
        {
          label: '一级 1',
          children: [
            {
              label: '二级 1-1'
            }
          ]
        },
        {
          label: '一级 2',
          children: [
            {
              label: '二级 2-1'
            },
            {
              label: '二级 2-2'
            }
          ]
        },
        {
          label: '一级 3',
          children: [
            {
              label: '二级 3-1'
            },
            {
              label: '二级 3-2'
            }
          ]
        }
      ],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  watch: {
    str(val) {
      this.$refs.treeForm.filter(val)
    }
  },
  created() {
    this.showData = [...this.data]
  },
  computed: {
    realVisible: {
      get() {
        return this.show
      },
      set(v) {
        this.$emit('update:show', v)
      }
    }
  },
  methods: {
    isshow(v) {
      this.realVisible = v
    },
    filterNode(value, data) {
      console.log(value, data)
      if (!value) {
        return true
      } else {
        return data.label.includes(value)
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>